import java.util.concurrent.*;

class MyResource implements Runnable{
      private String LockA;
      private String LockB;

      public MyResource(String A, String B) {
          this.LockA = A;
          this.LockB = B;
      }
      @Override
      public void run() {
          synchronized (LockA){
              System.out.println(Thread.currentThread().getName()+"占据"+ LockA+"想占有"+ LockB);
              try {
                  Thread.sleep(1000);
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
              synchronized (LockB){
                  System.out.println(Thread.currentThread().getName()+"占据" + LockB);
              }
          }
      }
  }


